import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Register from '@/components/Register'
import Login from '@/components/Login'
import CateList from "@/components/CateList";
import Cart from "../components/Cart";
import {Upload} from "element-ui";
import Detail from "../components/Detail";
import AddGoods from "../components/admin/AddGoods";
import AddTag from "../components/admin/AddTag";
import Index from "../components/Index";

Vue.use(Router);

export default new Router({
  routes: [
    {
        path: '/',
        name: 'Index',
        component: Index
    },
    {
        path: '/addtag',
        name: 'AddTag',
        component: AddTag
    },
    {
        path: '/addgoods',
        name: 'AddGoods',
        component: AddGoods
    },
    {
        path: '/detail',
        name: 'Detail',
        component: Detail
    },
    {
        path: '/upload',
        name: 'Upload',
        component: Upload
    },
    {
        path: '/cart',
        name: 'Cart',
        component: Cart,
        beforeEnter: (to, from, next) => {
          console.log(to);
          console.log(from);
          console.log(next);
          if (sessionStorage.getItem('username')){
            next()
          }else {
            next({'path': '/login', 'query': {'collback': to.fullPath}})
          }
        }
    },
    // {
    //     path: '/',
    //     name: 'CateList',
    //     component: CateList
    // },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/reg',
      name: 'Register',
      component: Register
    },
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
  ]
})
